﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using KeRui.Common;
public partial class Manage_Cms_subjectList : System.Web.UI.Page
{
    
    protected List<KeRui.Model.CmsNode> listNode;
    protected List<KeRui.Model.CmsNode> listCmsNode;
    protected List<KeRui.Model.CmsTemplateFile> listCmsTemplateFile;

    protected int siteid = PageRequest.GetInt("siteid",-1);
    public string act = PageRequest.GetString("act");
    protected int nid = PageRequest.GetInt("nid", -1);

    protected ManageErrMsg nsb = new ManageErrMsg();
    protected KeRui.BLL.CmsTemplateFile bllCmsTemplateFile = new KeRui.BLL.CmsTemplateFile();
    protected KeRui.BLL.CmsTemplateFile bllTemplateFile = new KeRui.BLL.CmsTemplateFile();
    protected KeRui.BLL.CmsNode bllCmsNode = new KeRui.BLL.CmsNode();
    protected KeRui.Model.CmsTemplateFile mTemplateFile = new KeRui.Model.CmsTemplateFile();

    protected void Page_Load(object sender, EventArgs e)
    {
        listNode = bllCmsNode.GetList("SiteID='" + siteid + "' and NodeName='专题' and Depth='1'");

        int NodeID = -1;
        foreach (KeRui.Model.CmsNode modelNode in listNode)
        {
            NodeID = modelNode.NodeID;
        }

        listCmsNode = bllCmsNode.GetList("SiteID='" + siteid + "' and ParentID='"+NodeID+"'");

        if (act == "del")
        {
            delete();
        }

    }

    public void delete()//删除模板
    {
        ManageHelper.CheckAdminPower("site_templatedel_" + siteid);//权限
        int FileID = PageRequest.GetInt("FileID", -1);
        mTemplateFile = bllTemplateFile.GetModel(FileID);//获得模板
        KeRui.BLL.Common.DelFile(mTemplateFile.FilePath, 1);//删除模板文件
        bllTemplateFile.Delete(FileID);//删除模板,和附加字段
        bllCmsNode.Delete(nid);//删除节点
        //删除Subjects附加表的中的数据
        KeRui.BLL.CmsTemplateSubjectsAttr BLLCmsTemplateSubjectsAttr = new KeRui.BLL.CmsTemplateSubjectsAttr();
        BLLCmsTemplateSubjectsAttr.Delete(BLLCmsTemplateSubjectsAttr.GetList("FileID=" + FileID)[0].ID);
        ManageHelper.AddLog("site_templatedel_" + siteid, "删除了“" + mTemplateFile + "”专题模板文件。");
        Response.Redirect("subjectList.aspx?siteid=" + siteid + "&sucmsg=删除成功!");
    }
}
